<?php
/*
+--------------------------------------------------------------------------
|   AffiliStore 2
|   ========================================
|   Web: http://www.affilistore.com
|   Email: admin (at) affilistore (dot) com
|	License Type: AffiliStore 2 is NOT open source software and limitations apply 
|   Licence Info: Visit AffiliStore website and click on 'Licence'
+--------------------------------------------------------------------------
*/
error_reporting(E_ALL ^ E_NOTICE);

set_include_path(PATH_SEPARATOR . dirname(realpath(__FILE__)) . '/' . 'classes/' . 
				 PATH_SEPARATOR . dirname(realpath(__FILE__)) . '/' . 
				 PATH_SEPARATOR . get_include_path());
require_once('includes/connect.php');
require_once('includes/functions.php');
require_once('includes/head.inc.php');
require_once('includes/fixlist.inc.php');

// begin cache mod
if ($navOpt[15] == 1 && is_writable('cache')) {
include("includes/begin_caching.php");
}

// require template class
include_once("classes/xtpl/xtemplate.class.php");

// begin XTemplate	
$body = new XTemplate ("skins/".$configSkin['value']."/index.tpl");

	//--------- Outside of the switch, add the following to all --------//
	// parsing of the side bars in the below switch will prevent items
	// from showing on certain pages within the site.

	// start content boxes
	$body->assign("INSTALLDIR",$installDir['value']);
	$body->assign("SKIN",$configSkin['value']);
	
	$getConfigTitle = mysql_query("SELECT * FROM affiliSt_config WHERE name = 'adWebTitle'");
	$configTitle = mysql_fetch_assoc($getConfigTitle);
	$getLogoImage = mysql_query("SELECT * FROM affiliSt_config WHERE name = 'adLogo'");
	$logoImage = mysql_fetch_assoc($getLogoImage);
	$getAltTag = mysql_query("SELECT * FROM affiliSt_config WHERE name = 'adLogoAlt'");
	$altTag = mysql_fetch_assoc($getAltTag);
	if ($logoImage['value'] == NULL) {
	$body->assign("LOGO",'<h1>'.$altTag['value'].'</h1>');
	} else {
	$body->assign("LOGO",'<img src="'.$logoImage['value'].'" alt="'.$altTag['value'].'" align="left" />');
	}
	$getConfigStrap = mysql_query("SELECT * FROM affiliSt_config WHERE name = 'adWebStrap'");
	$configStrap = mysql_fetch_assoc($getConfigStrap);
	
	// page numbers for titles
	if (isset($_GET['pageNum_product'])) {
	$pagenumtitle = 'Page '.($_GET['pageNum_product']).' | ';
	} else {
	$pagenumtitle = '';
	}
	
	// homelink
	$body->assign("HOMELINK",$installDir['value']);
	
	// add page links
	include("includes/pagelinkstop.inc.php");
	$body->assign("PAGELINKSTOP",$box_content);
	$body->assign("HOMEPAGELI",'topNavOff');
	$body->assign("HOMEPAGELINK",'topLinkOff" style="color:#ffffff;');
	include("includes/pagelinkstopsub.inc.php");
	$body->assign("PAGELINKSTOPSUB",$box_content);
	include("includes/pagelinksfoot.inc.php");
	$body->assign("FOOTLINKS",$box_content);
	
	// add generate navigation if set
	if ($navOpt[0] == 1) {
	include("includes/categories.inc.php");
	$body->assign("CATEGORIES",$box_content);
	}
	// add built navigation if set
	if ($navOpt[1] == 1) {
	include("includes/navcategories.inc.php");
	$body->assign("NAVCATEGORIES",$box_content);
	}
	// add featured product if set
	if ($navOpt[2] == 1) {
	include("includes/featureproducts.inc.php");
	$body->assign("FEATUREPROD",$box_content);
	}
	// add popular products if set
	if ($navOpt[3] == 1) {
	include("includes/popularprod.inc.php");
	$body->assign("POPULARPROD",$box_content);
	}
	// add user history if set
	if ($navOpt[16] == 1) {
	include("includes/userhistory.inc.php");
	$body->assign("USERHISTORY",$box_content);
	}
	// add tags if set
	if ($navOpt[8] == 1) {
	include("includes/tagcloud.inc.php");
	$body->assign("TAGS",$box_content);
	}
	// add news summaries if set
	if ($navOpt[6] == 1 && $_GET['case'] != 'news') {
	include("includes/news.inc.php");
	$body->assign("NEWS",$box_content);
	}
	// add links dir if set
	if ($navOpt[4] == 1) {
		if ($navOpt[7] == 1) {
		// html perma
		$body->assign("LINKDIR",'<a href="'.$installDir['value'].'links/1.html">Links</a>');
		} else {
		// php link
		$body->assign("LINKDIR",'<a href="'.$installDir['value'].'index.php?case=links&ld=1">Links</a>');
		}
	}
	// add page links if set
	if ($navOpt[5] == 1) {
	include("includes/pagelinks.inc.php");
	$body->assign("PAGELINKS",$box_content);
	}
	// add location bar, move this block of code to the bottom, after some page type is handled
	/*
	include("includes/location.inc.php");
	$body->assign("LOCATION",$box_content);
	*/
	// add search
	include("includes/search.inc.php");
	$body->assign("SEARCHPROD",$box_content);
	
	//------------ begin switch page type options ------------//
	
	// ---------- prod category
	switch ($_GET['case']) {
	case "products":
	$body->assign("META_TITLE",$pagenumtitle.str_replace('-', ' ', strip_tags($_GET['pc'])).' - '.$configTitle['value']);
	$body->assign("META_KEYWORDS",str_replace('-', ' ', strip_tags($_GET['pc'])).', '.$configTitle['value']);
	$body->assign("META_DESCRIPTION",str_replace('-', ' ', strip_tags($_GET['pc'])).' - '.$configTitle['value']);
	$body->assign("PAGETITLE",'<h1>'.str_replace('-', ' ', strip_tags($_GET['pc'])).'</h1>');
	include("includes/subcategories.inc.php");
	$body->assign("SUBNAV",$box_content);
	include("includes/products.inc.php");
	$body->assign("PRODS",$box_content);
	include("includes/pagination.inc.php");
	$body->assign("PAGINATION",$box_content);
	include("includes/pulldownbrands.inc.php");
	$body->assign("PULLDOWNPROD",$box_content);
	$body->assign("MIDSTYLE",'content-a"');
	$body->assign("FLOATSTYLE",'content-float-right-a');
	$body->parse("body.sideNavRight");
	break;
	
	// ---------- prod brand
	case "subproducts":
	$body->assign("META_TITLE",$pagenumtitle.str_replace('-', ' ', strip_tags($_GET['pb'])).' '.str_replace('-', ' ', strip_tags($_GET['pc'])).' - '.$configTitle['value']);
	$body->assign("META_KEYWORDS",str_replace('-', ' ', strip_tags($_GET['pb'])).', '.str_replace('-', ' ', strip_tags($_GET['pc'])).', '.$configTitle['value']);
	$body->assign("META_DESCRIPTION",str_replace('-', ' ', strip_tags($_GET['pb'])).', '.str_replace('-', ' ', strip_tags($_GET['pc'])).' - '.$configTitle['value']);
	$body->assign("PAGETITLE",'<h1>'.str_replace('-', ' ', strip_tags($_GET['pb'])).' '.str_replace('-', ' ', strip_tags($_GET['pc'])).'</h1>');
	include("includes/subcategories.inc.php");
	$body->assign("SUBNAV",$box_content);
	include("includes/products.inc.php");
	$body->assign("PRODS",$box_content);
	include("includes/pagination.inc.php");
	$body->assign("PAGINATION",$box_content);
	include("includes/pulldownbrands.inc.php");
	$body->assign("PULLDOWNPROD",$box_content);
	$body->assign("MIDSTYLE",'content-a"');
	$body->assign("FLOATSTYLE",'content-float-right-a');
	$body->parse("body.sideNavRight");
	break;
	
	// ---------- prod page
	case "product":
	$body->assign("META_TITLE",$row_product["prodName"]);
	$body->assign("META_KEYWORDS",$row_product["prodName"].', '.$row_product["prodBrand"].' '.$row_product["prodCategory"].', '.$configTitle['value']);
	$body->assign("META_DESCRIPTION",$row_product["prodName"].', '.$row_product["prodBrand"].' '.$row_product["prodCategory"].' - '.$configTitle['value']);
	$body->assign("PAGETITLE",'<h1>'.$row_product["prodName"].'</h1>');
		if (isset($_GET['savelink'])) {
		$body->assign("NOINDEXTAG",'<meta name="robots" content="noindex,nofollow" />');
		}
	include("includes/singleproducts.inc.php");
	$body->assign("PRODS",$box_content);
	include("includes/comments.inc.php");
	$body->assign("COMMENTS",$box_content);
	include("includes/addcomments.inc.php");
	$body->assign("ADDCOMMENTS",$box_content);
	include("includes/compareproducts.inc.php");
	$body->assign("COMPAREPRODS",$box_content);
	include("includes/products.inc.php");
	$body->assign("SIMILARPRODS",$box_content);
	$body->assign("MIDSTYLE",'content-a');
	$body->assign("FLOATSTYLE",'content-float-right-a');
	$body->parse("body.sideNavRight");
	break;
	
	// ---------- search
	case "search":
	$body->assign("META_TITLE",$pagenumtitle.strip_tags($_GET['ps']).' Search Results | '.$configTitle['value']);
	$body->assign("META_KEYWORDS",strip_tags($_GET['ps']).', '.$configTitle['value']);
	$body->assign("META_DESCRIPTION",strip_tags($_GET['ps']).' - '.$configTitle['value']);
	$body->assign("PAGETITLE",'<h1>Results for \''.strip_tags($_GET['ps']).'\'</h1>');
	include("includes/products.inc.php");
	$body->assign("PRODS",$box_content);
	include("includes/pagination.inc.php");
	$body->assign("PAGINATION",$box_content);
	include("includes/pulldownbrands.inc.php");
	$body->assign("PULLDOWNPROD",$box_content);
	$body->assign("MIDSTYLE",'content-a"');
	$body->assign("FLOATSTYLE",'content-float-right-a');
	$body->parse("body.sideNavRight");
	break;
	
	// ---------- built nav top
	case "categories":
	$body->assign("META_TITLE",$pagenumtitle.$navC['name'].' - '.$configTitle['value']);
	$body->assign("META_KEYWORDS",$navC['name'].', '.$configTitle['value']);
	$body->assign("META_DESCRIPTION",$navC['name'].' - '.$configTitle['value']);
	$body->assign("PAGETITLE",'<h1>'.$navC['name'].'</h1>');
	$body->assign("NAVPAGECONTENT",$navC['content']);
	include("includes/subnavcategories.inc.php");
	$body->assign("SUBNAV",$box_content);
	include("includes/products.inc.php");
	$body->assign("PRODS",$box_content);
	include("includes/pagination.inc.php");
	$body->assign("PAGINATION",$box_content);
	include("includes/pulldownbrands.inc.php");
	$body->assign("PULLDOWNPROD",$box_content);
	$body->assign("MIDSTYLE",'content-a"');
	$body->assign("FLOATSTYLE",'content-float-right-a');
	$body->parse("body.sideNavRight");
	break;
	
	// ---------- built nav sub
	case "subcategories":
	$body->assign("META_TITLE",$pagenumtitle.$navB['name'].' '.$navC['name'].' - '.$configTitle['value']);
	$body->assign("META_KEYWORDS",$navB['name'].', '.$navC['name'].', '.$configTitle['value']);
	$body->assign("META_DESCRIPTION",$navB['name'].' '.$navC['name'].' - '.$configTitle['value']);
	$body->assign("PAGETITLE",'<h1>'.$navB['name'].' '.$navC['name'].'</h1>');
	$body->assign("NAVPAGECONTENT",$navB['content']);
	include("includes/subnavcategories.inc.php");
	$body->assign("SUBNAV",$box_content);
	include("includes/products.inc.php");
	$body->assign("PRODS",$box_content);
	include("includes/pagination.inc.php");
	$body->assign("PAGINATION",$box_content);
	include("includes/pulldownbrands.inc.php");
	$body->assign("PULLDOWNPROD",$box_content);
	$body->assign("MIDSTYLE",'content-a"');
	$body->assign("FLOATSTYLE",'content-float-right-a');
	$body->parse("body.sideNavRight");
	break;
	
	// ---------- links
	case "links":
	$body->assign("META_TITLE",$configTitle['value'].' - Links');
	$body->assign("PAGETITLE",'<h1>Links</h1>');
	include("includes/links.inc.php");
	$body->assign("LINKS",$box_content);
	require_once('includes/cron.inc.php');
	include("includes/linkcategories.inc.php");
	$body->assign("PRODS",$box_content);
		if (isset($_GET['add'])) {
		include("includes/addlink.inc.php");
		$body->assign("ADDLINK",$box_content);
		}
	$body->assign("MIDSTYLE",'content-b');
	$body->assign("FLOATSTYLE",'content-float-right');
	$body->parse("body.sideNavLeft");
	break;
	
	// ---------- page top
	case "page":
	$body->assign("META_TITLE",$pageDetails['name'].' - '.$configTitle['value']);
	$body->assign("META_KEYWORDS",$pageDetails['name'].', '.$configTitle['value']);
	$body->assign("META_DESCRIPTION",$pageDetails['name'].' - '.$configTitle['value']);
	include("includes/page.inc.php");
	$body->assign("PAGE",$box_content);
	$body->assign("MIDSTYLE",'content-b"');
	$body->assign("FLOATSTYLE",'content-float-right');
	$body->parse("body.sideNavLeft");
	break;
	
	// ---------- page sub
	case "subpage":
	$body->assign("META_TITLE",$pageSubDetails['name'].' - '.$pageDetails['name'].' - '.$configTitle['value']);
	$body->assign("META_KEYWORDS",$pageSubDetails['name'].', '.$pageDetails['name'].', '.$configTitle['value']);
	$body->assign("META_DESCRIPTION",$pageSubDetails['name'].' - '.$pageDetails['name'].' - '.$configTitle['value']);
	include("includes/page.inc.php");
	$body->assign("PAGE",$box_content);
	$body->assign("MIDSTYLE",'content-b"');
	$body->assign("FLOATSTYLE",'content-float-right');
	$body->parse("body.sideNavLeft");
	break;
	
	// ---------- news homepage
	case "news":
	$body->assign("META_TITLE",'News - '.$configTitle['value']);
	$body->assign("META_KEYWORDS",$configTitle['value']);
	$body->assign("META_DESCRIPTION",$configTitle['value']);
	$body->assign("PAGETITLE",'');
	include("includes/newspage.inc.php");
	$body->assign("PAGE",$box_content);
	$body->assign("MIDSTYLE",'content-b"');
	$body->assign("FLOATSTYLE",'content-float-right');
	$body->parse("body.sideNavLeft");
	break;
	
	// ---------- news item
	case "newsitem":
	$body->assign("META_TITLE",$newsItemsSingle['name'].' - '.$configTitle['value']);
	$body->assign("META_KEYWORDS",$newsItemsSingle['name'].', '.$configTitle['value']);
	$body->assign("META_DESCRIPTION",$newsItemsSingle['name'].' - '.$configTitle['value']);
	$body->assign("PAGETITLE",'');
	include("includes/newspage.inc.php");
	$body->assign("PAGE",$box_content);
	include("includes/comments.inc.php");
	$body->assign("COMMENTS",$box_content);
	include("includes/addcomments.inc.php");
	$body->assign("ADDCOMMENTS",$box_content);
	$body->assign("MIDSTYLE",'content-b"');
	$body->assign("FLOATSTYLE",'content-float-right');
	$body->parse("body.sideNavLeft");
	break;
	
	// ---------- merchant comments
	case "stores":
	$body->assign("META_TITLE",str_replace('-', ' ', strip_tags($_GET['merchant'])).' Store Review - '.$configTitle['value']);
	$body->assign("META_KEYWORDS",str_replace('-', ' ', strip_tags($_GET['merchant'])).', Store Review, '.$configTitle['value']);
	$body->assign("META_DESCRIPTION",str_replace('-', ' ', strip_tags($_GET['merchant'])).' Store Review - '.$configTitle['value']);
	include("includes/comments.inc.php");
	$body->assign("COMMENTS",$box_content);
	include("includes/addcomments.inc.php");
	$body->assign("ADDCOMMENTS",$box_content);
	$body->assign("MIDSTYLE",'content-a');
	$body->assign("FLOATSTYLE",'content-float-right-a');
	$body->parse("body.sideNavRight");
	break;

	// ---------- account register
	case "account":
		switch ($_GET['act']){
			case 'register':
				$body->assign("META_TITLE",$configTitle['value']);
				$body->assign("META_KEYWORDS",$configTitle['value']);
				$body->assign("META_DESCRIPTION",$configStrap['value'].' - '.$configTitle['value']);
				$body->assign("HOMEPAGELI",'topNavOn');
				$body->assign("HOMEPAGELINK",'topLinkOn');
				
				include("includes/accountRegister.inc.php");
				$body->assign("PAGE",$box_content);
				break;
				
			case 'login':
				$body->assign("META_TITLE",$configTitle['value']);
				$body->assign("META_KEYWORDS",$configTitle['value']);
				$body->assign("META_DESCRIPTION",$configStrap['value'].' - '.$configTitle['value']);
				$body->assign("HOMEPAGELI",'topNavOn');
				$body->assign("HOMEPAGELINK",'topLinkOn');
				include("includes/accountLogin.inc.php");
				$body->assign("PAGE",$box_content);				
				$body->assign("MIDSTYLE",'content-login');
				$body->assign("FLOATSTYLE",'content-float-right-a');
				//$body->parse("body.sideNavLeft");
				//$body->parse("body.sideNavRight");				
				break;
			case 'forgotpassword':
				$body->assign("META_TITLE",$configTitle['value']);
				$body->assign("META_KEYWORDS",$configTitle['value']);
				$body->assign("META_DESCRIPTION",$configStrap['value'].' - '.$configTitle['value']);
				$body->assign("HOMEPAGELI",'topNavOn');
				$body->assign("HOMEPAGELINK",'topLinkOn');
				include("includes/accountForgotPassword.inc.php");
				$body->assign("PAGE",$box_content);				
				$body->assign("MIDSTYLE",'content-login');
				$body->assign("FLOATSTYLE",'content-float-right-a');
				break;
		}		
	break;	
	
	// ---------- homepage and default setting
	default:
	$body->assign("META_TITLE",$configTitle['value']);
	$body->assign("META_KEYWORDS",$configTitle['value']);
	$body->assign("META_DESCRIPTION",$configStrap['value'].' - '.$configTitle['value']);
	$body->assign("HOMEPAGELI",'topNavOn');
	$body->assign("HOMEPAGELINK",'topLinkOn');
	include("includes/page.inc.php");
	$body->assign("PAGE",$box_content);
	$body->assign("MIDSTYLE",'content');
	$body->assign("FLOATSTYLE",'content-float-right');
	$body->parse("body.sideNavLeft");
	$body->parse("body.sideNavRight");
	
	// end switch ->
	}
	
	// add location bar, move here because some information need manipulating first before display in this breadcrumbs
	include("includes/location.inc.php");
	$body->assign("LOCATION",$box_content);
	
	// indicate is the user has loged in or not
	include_once 'includes/models/Auth.php';
	$auth = Auth::getInstance();
	if($auth->hasIdentity()){
		$body->parse("body.logedIn");
	} else { 
		$body->parse("body.notLogedIn");
	}
	
// parse and spit out final document
$body->parse("body");
$body->out("body");

// end cache mod
if ($navOpt[15] == 1 && is_writable('cache')) {
include("includes/end_caching.php");
}
?>